import play.*;
import play.libs.*;

import java.util.*;

import com.avaje.ebean.*;

import models.*;

public class Global extends GlobalSettings {

    public void onStart(Application app) {
        InitialData.insert(app);
    }

    static class InitialData {

        public static void insert(Application app) {
            if(Ebean.find(Role.class).findRowCount() == 0) {

                Map<String,List<Object>> all = 
                    (Map<String,List<Object>>)Yaml.load("initial-data.yml");

                Ebean.save(all.get("roles"));

            }
            if(Ebean.find(Utilisateur.class).findRowCount() == 0) {

                Map<String,List<Object>> all = 
                    (Map<String,List<Object>>)Yaml.load("initial-data.yml");

                Ebean.save(all.get("utilisateurs"));

            }
            if(Ebean.find(Etat.class).findRowCount() == 0) {

                Map<String,List<Object>> all = 
                    (Map<String,List<Object>>)Yaml.load("initial-data.yml");

                Ebean.save(all.get("etats"));

            }
            if(Ebean.find(Message.class).findRowCount() == 0) {

                Map<String,List<Object>> all = 
                    (Map<String,List<Object>>)Yaml.load("initial-data.yml");

                Ebean.save(all.get("messages"));

            }
            if(Ebean.find(AppelOffre.class).findRowCount() == 0) {

                Map<String,List<Object>> all = 
                    (Map<String,List<Object>>)Yaml.load("initial-data.yml");

                Ebean.save(all.get("appelsoffres"));

            }
        }

    }

}